package main

import (
	"fmt"
	"time"
)

func main()  {

	//获取当前时间
	now := time.Now()
	fmt.Printf("now = %v,type = %T\n",now,now)

	//通过now获取对应的年月日
	fmt.Printf("年%v\n",now.Year())
	fmt.Printf("月%v\n",now.Month())
	fmt.Printf("月%v\n",int(now.Month()))
	fmt.Printf("日%v\n",now.Day())
	fmt.Printf("时%v\n",now.Hour())
	fmt.Printf("分%v\n",now.Minute())
	fmt.Printf("秒%v\n",now.Second())
	
	//格式化时期
	fmt.Printf("时间：%d-%d-%d %d:%d:%d\n",now.Year(),now.Month(),now.Day(),
	now.Hour(),now.Minute(),now.Second())

	nowTime := fmt.Sprintf("时间：%d-%d-%d %d:%d:%d",now.Year(),now.Month(),now.Day(),
	now.Hour(),now.Minute(),now.Second())
	fmt.Printf("%v\n",nowTime)

	//每个1秒输出一个数
	for i:=0;i<5;i++ {
		fmt.Println(i)
		time.Sleep(time.Second)
	}

	//获取时间戳
	fmt.Printf("unix时间戳%v,unixnano时间戳%v\n",now.Unix(),now.UnixNano())
}

